package com.controller;

import com.entity.Response;
import com.entity.pojo.WrTeam;
import com.entity.vo.TeamVo;
import com.service.TeamService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/team")
public class TeamController {

    @Resource
    private TeamService teamService;

    @GetMapping
    public Response listTeam() {
        List<TeamVo> teamVoList = teamService.listTeam();
        return new Response().setSuccess().appendMsg("list", teamVoList);
    }

    @PostMapping
    public Response insertTeam(@RequestBody WrTeam wrTeam) {
        int res = teamService.insertTeam(wrTeam);
        return res > 0 ? new Response().setSuccess() : new Response().setFailed();
    }

    @PutMapping
    public Response updateTeam(@RequestBody TeamVo wrTeam) {
        int res = teamService.updateTeam(wrTeam);
        return res > 0 ? new Response().setSuccess() : new Response().setFailed();
    }

    @DeleteMapping
    public Response deleteTeam(@RequestParam("id") Integer id) {
        int res = teamService.deleteTeam(id);
        return res > 0 ? new Response().setSuccess() : new Response().setFailed();
    }
}
